<template>
  <!-- 公司印章管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title" /> -->
      
      <!--v-btnPermission="'lu_0014_exp_06'"-->
      <!-- <excel
        ref="exportAll"
        class="ml12"
        file-name="西南公司印章"
        is-click-generate="false"
      >
        <a-button
          slot="excelBtn"
          v-btnPermission="'oa_012_exp_02'"
          type="primary"
          icon="download"
          :loading="loading"
          @click="exportAll"
        >
          导出
        </a-button>
      </excel> -->
      <!-- 表格 -->
      <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :export-permission="{ select: 'oa_012_exp_02', all: 'oa_012_exp_02' }"
        :export-config="{ use: true, select: '西南公司印章', all: '西南公司印章' }"
      >
      <a-button
        slot="prefix"
        slot-scope="ref"
        v-btnPermission="'oa_012_add_01'"
        class="mb12 mr20"
        icon="plus"
        type="primary"
        @click="handleManage(2)"
      >
        新增印章
      </a-button>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
        <template
          slot="borrowTime"
          slot-scope="text, record"
        >
          {{ record.borrowTime || '—' }}
        </template>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
          <a @click="handleManage(0, record)">查看</a>
          <a
            v-if="record.creatorId == id"
            @click="handleManage(1, record)"
          >编辑</a>
          <a
            v-if="record.creatorId == id"
            class="del_btn"
            @click="handleRemove(record)"
          >删除</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { getList, remove, getLabels } from '@/api/office/sealManage/companySealStatus' // api
import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject.vue'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置

const searchArr = [
    {
        name: '单位',
        valueKey: 'unitId',
        type: Selector,
        selectType: '12',
        urlType: 'union'
    },

    {
        name: '印章名称',
        type: 'input',
        value: 'title'
    }
]
const columnsBgr = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    scopedSlots: { customRender: 'index' }
  },
  {
    title: '单位名称',
    ellipsis: true,
    dataIndex: 'unitName',
  },
  {
    title: '印章名称',
    ellipsis: true,
    dataIndex: 'title',
  },
  {
    title: '保管部门',
    ellipsis: true,
    dataIndex: 'careDepartmentName',
  },
  {
    title: '保管人',
    ellipsis: true,
    dataIndex: 'careName',
  },
  {
    title: '联系电话',
    ellipsis: true,
    dataIndex: 'phone',
  },
  {
    title: '印章状态',
    ellipsis: true,
    dataIndex: 'statusName',
  },
  {
    title: '外借时间',
    ellipsis: true,
    dataIndex: 'borrowTime',
    scopedSlots: { customRender: 'borrowTime' },
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
const columns = [
    {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        scopedSlots: { customRender: 'index' }
    },
    {
        title: '单位名称',
      width: 220,
      dataIndex: 'unitName'
    },
    {
        title: '印章名称',
        dataIndex: 'title',
      width: 220
    },
    {
        title: '保管部门',
      width: 220,
      dataIndex: 'careDepartmentName'
    },
    {
        title: '印章状态',
      width: 120,
      dataIndex: 'statusName'
    },
    {
        title: '外借时间',
      width: 120,
      dataIndex: 'borrowTime',
        scopedSlots: { customRender: 'borrowTime' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
  name:'a'+Date.now(),
  extends: new BasePage(),
    components: {
        // STable,
    },
    data() {
      this.columns = JSON.parse(sessionStorage.getItem('ycloud-user_info')).currentPost.postCode==='COAYZGL' ? columnsBgr : columns
        this.searchArr = searchArr
        return {
            loading: false,
            totalSize: null,
            queryParam: {}, // 查询参数
            id: JSON.parse(sessionStorage.getItem('ycloud-user_info'))?.employee?.userId, //登录人id
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
                return getList(requestParameters).then((res) => {
                    this.totalSize = res.totalSize
                    return res
                })
            }, // 加载数据方法 必须为 Promise 对象
            editModel: 0
        }
    },
    computed: {},
    watch: {},
    created() {},
    methods: {
        /**
         * 搜索
         */
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        /**
         * 删除
         */
        handleRemove(e) {
            this.$confirm({
                title: '温馨提示',
                content: `确认删除${e.title}？`,
                onOk: () => {
                    return remove(e.id).then(() => {
                        this.$message.success('删除成功！')
                        this.search()
                    })
                }
            })
        },
        /**
         * 操作
         */
        handleManage(type, record) {
            this.editModel = type
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                path: '/sealManagement/companySealStatus/add',
                query
            })
        },
        /**
         * 导出
         */
        exportAll() {
            this.loading = true
            let searchData = Object.assign(
                {
                    pageSize: this.totalSize,
                    pageNo: 1
                },

                this.queryParam
            )
            getList(searchData)
                .then((res) => {
                    res.data.forEach((item, index) => {
                        item.index = index
                    })
                    this.loading = false
                    this.$refs.exportAll.setDataAndGenerate(res.data)

                    this.$message.success('导出成功')
                })
                .catch(() => {
                    this.loading = false
                })
        }
    },
    mounted() {
        // this.$refs.exportAll.tableToExcelFile(this.$refs.table)
    }
}
</script>
